簡體   English   中英

在Mongodb集合數組字段上查找元素

[英]Finding element on Mongodb collection array field

我的收藏集:

{ "_id" : ObjectId("5817a06de4e150a1418b4567"),  
  "idStore" : [
"58177ca2e4e15041058b4567", 
"5817a192e4e150d7098b4567",         
"5817bbb3e4e15020778b4567"
]}

db.collection('atendimento').aggregate([{ $match: { dataI:{ $gt: fDate },     status: 'OCUPADO' } }, 
            { $group: {_id: {"idLoja":"$idLoja", "venda":"$sim"},  qtd:     {"$sum":1}} },  
             {$sort: {'_id.idLoja': 1, '_id.venda': 1}}]).toArray(function(err,     result) {
            var vIdLoja = '';
            for (var x = 0; x < result.length; x++) {   
                vIdLoja = result[x]._id.idLoja;
.
.
.
    db.collection('usuario').find({idStore: { $elemMatch: { $gte: vIdLoja, $lte: vIdLoja } }}).toArray(function(err, result) {

要么:

db.collection('usuario').find({idStore: vIdLoja}).toArray(function(err, result) {

結果是相同的: empty/undefined驅動程序:MongoClient

我該如何解決這個問題?

由於idStore是一個簡單的字符串數組,因此您可以直接查詢該字段:

db.collection('usuario').find({ idStore: "5817a192e4e150d7098b456" }, ...);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM