findOne() return a object with 'Document'


When I use “findOne”, the result is an Object beginning with

I20170420-12:02:05.413(2)? Document {
I20170420-12:02:05.414(2)?   _id: 'PG742WBoLnz5pKPDk',
I20170420-12:02:05.414(2)?   name: 'eius',
I20170420-12:02:05.415(2)?   number: 34129,
I20170420-12:02:05.415(2)?   part: 'application',
I20170420-12:02:05.415(2)?   active: true,
I20170420-12:02:05.416(2)?   cron: 1,

And then I try to compare this with an object, the result is false.
For perform that, I need to convert both to array for “clear” the “Document”…

I was try to realize a fetch() but I have an error “Equipments.findOne(…).fetch is not a function”

What is it ?

Thanks ! :smiley:

someCollection.findOne() is exactly equivalent to someCollection.find().fetch()[0].

Either of those will return a single document (an object) from myCollection.

That’s generally correct. If you do:

const a = { a:1 };
const b = { a:1 };
console.log(a === b);

You will see false in your log.

With my entire code, my problem will be clearer :slight_smile:

it('insert', function() {
      let eqpt = {
        name: faker.lorem.word(),
        // etc

      const eqptId = Equipments.insert(eqpt); // Insert and retrieve the _id
      const eqptUpdated = _.extend({_id: eqptId}, eqpt); // Add the _id

      // Fonctionnal
      assert.deepEqual(_.pairs(Equipments.findOne(eqptId)), _.pairs(eqptUpdated));

      // Not Fonctionnal
      assert.deepEqual(Equipments.findOne(eqptId), eqptUpdated);

I think that assert.deepEqual(Equipments.findOne(eqptId), eqptUpdated); should work. I’ve just written a small server-side code block which works using node’s inbuilt assert.deepEquals.

Without try to use “[todos] (” skeleton, it’s functionnal.

I think no longer try to use the “[todos] (” skeleton. It’s too much complicated.

Are you using a package which can mutate the data when it’s written to the collection (like aldeed:collection2)?

If so, that may explain the non-equality.

yes, I use this package and the following:

# data