如何使用 java 脚本获取 BaasBox[0.9.2] 中的文档 ID

How to get document id's in BaasBox[0.9.2] using java script

我是 BaasBox 的新手。 我可以回答如何使用 javascript. 获取 BaasBox 集合中的所有文档 ID 吗? 提前致谢。

我已经尝试过这段代码,并且能够使用它进行管理。 希望它可以帮助某人。

BaasBox.loadCollection("Loyalties")
             .done(function(res) {
                 for (var i=0; i<res.length; i++){
                     if( res[i].email == "xyz@xyz.com")
                         console.log("result ", res[i].id);
                 }
            })
            .fail(function(error) {
              console.log("error ", error);
            })

我在使用 Baasbox Javascript SDK (loadCollectionWithParams()) 时遇到了问题,所以我在 javascript 使用 jquery 使用以下方法:

var collectionname = 'mycollection';
var query = 'title = "godzilla"';
var url = 'http://localhost:9000/document/' + collectionname + '?where=' + encodeURIComponent(query);

$.ajax({
    url: url,
    method: 'GET',
    dataType: 'json'
}).done(function(res) {
    console.log( res );
}).fail(function(error) {
    console.log( error );
});

在您的情况下,您希望通过电子邮件进行过滤,因此您可以将查询的值更改为类似以下内容:

var query = 'email = "xyz@xyz.com"';

请注意,要使查询生效,'title' 和 'email' 必须是文档中的一级键,换句话说,它们应该如下所示:

{
    "title": "godzilla",
    "email": "xyz@xyz.com"
}

来源:Baasbox Documentation