使用诸如['hello','there']之类的数组并将其存储在具有诸如
之类的模式的Mongoose文档中tags: { type: Array }
使用如下内容:
Something.create({ tags: ['hello', 'there']}, cb);
然后使用ShouldJS检查文档是否与我提供的数组匹配,我希望如此:
doc.tags.should.eql(['hello', 'there']);
但事实并非如此。如果我得到console.log doc标签:
[hello, there]
请注意,引号已经消失。 doc.tags确实是一个数组(我可以检查instanceof数组),我也可以使用带有
的应用程序doc.tags.should.have.keys('hello');
doc.tags.should.have.keys('there');
任何人都知道为什么我的阵列不再匹配了?
答案 0 :(得分:3)
你的数组不是真正的json Array
:它是MongooseArray
,还有其他方法。
要使should.eql
与mongoose数组一起使用,请先使用toObject()
:
doc.tags.toObject().should.eql(['hello', 'there']);