[英]Azure Cosmos DB (mongodb) find() with '$in' query not returning anything
我的文檔有一個名為“標簽”的字段,它是一個字符串數組。 我正在嘗試搜索在“標簽”中包含“關鍵字”的文檔。 但是,這似乎不適用於Azure Cosmos DB。 任何幫助表示贊賞。
編輯:根據評論者的要求,我用更完整的代碼示例替換了我以前的文章。
const MongoClient = require('mongodb').MongoClient;
const mongoConnectionString = process.env.MONGODB_CONNECTION_STRING;
const mongoOptions =
{
connectTimeoutMS: 0
}
var mongoDB;
MongoClient.connect(mongoConnectionString, (err, db) => {
if (err) throw err;
mongoDB = db.db('mydb');
mongoDB.collection('mycol', (err, collection) => {
if (err) throw err;
collection.find(
{tags: {$in:['keyword']}},
(err, cursor) => {
if (err) throw(err);
cursor.toArray((err, docs) => {
for (i = 0; i < docs.length; i++) {
console.log(JSON.stringify(docs));
db.close();
}
});
}
);
});
});
cosmos DB的魔術技巧是使用$ elemMatch。 結案。
mongoDB.collection('mycol', (err, collection) => {
if (err) throw err;
collection.find({tags: {$elemMatch:{$in : ['keyword']}}}).toArray((err, docs) => {
console.log(docs);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.