我需要写Azure Cosmos DB Mongo API DB的条件 我已经写了sp来获取所有数据,但是当我添加where条件时它不返回数据。
我需要有关在Mongo API中编写SP并返回与我保存的json相同的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.');
}