简体   繁体   English

console.log->文档{…}

[英]console.log -> Document { … }

When I apply "console.log" on an JS Object, the console output this thing : 当我在JS对象上应用“ console.log”时,控制台将输出以下内容:

I20170421-14:54:09.786(2)? Document {
I20170421-14:54:09.787(2)?   _id: 'KQ7mdidtcxsQsqNjr',
I20170421-14:54:09.787(2)?   name: 'eos test',
I20170421-14:54:09.787(2)?   number: 69526,
I20170421-14:54:09.788(2)?   part: 'bus',
I20170421-14:54:09.788(2)?   active: true,
I20170421-14:54:09.789(2)?   cron: 6,

What is this 'Document' ??? 这是什么“文件”? How I can remove to comapre this Object with the same without 'Document'... 我该如何删除该对象以使其与没有“文档”的对象相同?

I'm lost ! 我迷路了 !

This document is an output of 'findOne'. 该文档是“ findOne”的输出。 I use Meteor with some packages (mongo@1.1.16, aldeed:simple-schema, aldeed:collection2, mdg:validated-method, mdg:validation-error, dburles:collection-helpers). 我将Meteor与某些软件包一起使用(mongo@1.1.16,aldeed:simple-schema,aldeed:collection2,mdg:validated-method,mdg:validation-error,dburles:collection-helpers)。

Thanks :) 谢谢 :)

You could compare manually (obj2.field1 === obj2.field1) or just use JSON.stringify in both objects and compare the resulting string. 您可以手动比较(obj2.field1 === obj2.field1),也可以仅在两个对象中使用JSON.stringify并比较结果字符串。

But in your case I think you are not retrieving the object from mongo as you should. 但是在您的情况下,我认为您没有按应从mongo检索对象。 Use fetch() after the query: DocumentCollection.find({}).fetch() or just .findOne() instead. 查询后使用fetch():DocumentCollection.find({})。fetch()或仅使用.findOne()。

Also, if you want to compare 2 Meteor documents, you can use: 另外,如果要比较2个流星文档,则可以使用:

_.isEqual(doc1, doc2) (underscore) _.isEqual(doc1,doc2)(下划线)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM