我需要为 Azure Cosmos DB Mongo API DB 编写 where 条件我已经编写了 sp 来获取所有数据,但是当我添加 where 条件时它没有返回数据。
我需要帮助在 Mongo API 中编写 SP 并返回与我保存的相同 json 或具有选定属性的新 json
function sample(prefix) {
var collection = getContext().getCollection();
var filterQuery2 = 'SELECT * FROM root r where r.userName= "' + prefix + '"';
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
filterQuery2,
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
var body = { prefix: prefix, feed: feed[0] };
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}