Here's my issue.
On one side I have a plain object representation of a Mongoose object.
On the other side I have a Mongoose object coming straight from a findOne
in the database.
What I am trying to do is check if anything is different between two properties of the two object. Let's consider this kind of model for example:
{
_id: 'abc',
id: 'abc',
things: [{
_id: 'def',
id: 'def',
other_things: [{
_id: 'ghi',
id: 'ghi',
foo: 'bar'
}]
}]
}
I want to compare myplainobject.things
to mydbobject.things
.
But, using underscore
, _.isEqual(myplainobject.things, mydbobject.things)
always fails.
This is due to ids that are in the first case string
and in the other, ObjectID
.
While there are a lot of ways to compare an ObjectID
to a string
, is there an elegant way to compare objects?
Or do I have to implement my own solution that would loop through every subdocument and manually compare properties?