如何获取文档id's在BaasBox[0.9.2]中使用java脚本

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

本文关键字:BaasBox 脚本 java 获取 何获取 文档 id      更新时间:2023-09-26

我是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"answers"email"必须是文档中的一级密钥,换句话说,它们应该看起来像:

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

来源:Baasbox文档