Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ShouldJS比较Mongoose中的数组_Javascript_Node.js_Mongoose_Should.js - Fatal编程技术网

Javascript 使用ShouldJS比较Mongoose中的数组

Javascript 使用ShouldJS比较Mongoose中的数组,javascript,node.js,mongoose,should.js,Javascript,Node.js,Mongoose,Should.js,获取一个数组,如['hello','there'],并将其存储在Mongoose文档中,模式如下 tags: { type: Array } 使用诸如: Something.create({ tags: ['hello', 'there']}, cb); 然后使用ShouldJS检查文档是否与我提供的数组匹配,我希望: doc.tags.should.eql(['hello', 'there']); 但事实并非如此。如果我得到console.log文档标记: [hello, there]

获取一个数组,如['hello','there'],并将其存储在Mongoose文档中,模式如下

tags: { type: Array }
使用诸如:

Something.create({ tags: ['hello', 'there']}, cb);
然后使用ShouldJS检查文档是否与我提供的数组匹配,我希望:

doc.tags.should.eql(['hello', 'there']);
但事实并非如此。如果我得到console.log文档标记:

[hello, there] 
请注意,引号已消失。doc.tags确实是一个数组(我可以检查数组的instanceof),我还可以使用shouldjs

doc.tags.should.have.keys('hello');
doc.tags.should.have.keys('there');

有人知道为什么我的数组不再匹配了吗?

你的数组不是一个真正的json
array
:它是一个带有附加方法的
mongoosarray

要使
should.eql
与mongoose数组一起工作,请首先使用
toObject()


愚蠢的问题,可能是一种类型,但当你输出时,你会得到[hello,there]或['hello','there'],因为它们不会相等,你会得到这个问题的答案吗?我也一样issue@dworrad-不,我从来没想过。
doc.tags.toObject().should.eql(['hello', 'there']);