gpt4 book ai didi

node.js - 蒙哥错误: $all requires array

转载 作者:可可西里 更新时间:2023-11-01 10:43:55 26 4
gpt4 key购买 nike

我正在使用 sailsjs mongodb 和 node.js我在 mongodb 查询错误后收到错误请帮忙!
我想获得与 $all: [ senderID , sendToID ]

完全匹配的那些消息的结果这是我在 mongodb 中的文档“消息”。

{    "users": [        "52ed09e1d015533c124015d5",        "52ed4bc75ece1fb013fed7f5"     ],    "user_msgs": [],    "createdAt": ISODate("2014-02-04T11:59:53.220Z"),    "updatedAt": ISODate("2014-02-04T11:59:53.220Z"),    "_id": ObjectID("52f0d639b922c9142763c336")}

现在我要查询

    Message.find({ users : {  $all:  [ msg.sender ,   msg.sendTo ]  } })                    .done(function (err, detail) {                if (err) {                                  console.log(err)                  } else {                    console.log( detail)}          });

返回错误

{[MongoError:$all requires array] name:'MongoError'} 

我正在关注文档 http://docs.mongodb.org/manual/reference/operator/query/all/但仍然不知道是什么导致了问题

最佳答案

在 Waterline 中目前没有查询嵌入记录的方法。不过,您可以下拉到 sails-mongo 中的本地 mongo 驱动程序并运行查询。以下内容应该可以满足您的需求。

User.native(function(err, collection) {
collection.find({ users: {
$all: [ "52ed09e1d015533c124015d5", "52ed4bc75ece1fb013fed7f5" ]
}}).toArray(function(err, docs) {
// Do something here
});
});

关于node.js - 蒙哥错误: $all requires array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com