There is.
/* 0 */ { "_id" : ObjectId("541c03489c3009e80de19d6b"), "ts" : 1411121993, "close" : false, "users" : [ "7e8f5f8fc847bc6", "920299d58dc02ec" ], "__v" : 0 } /* 1 */ { "_id" : ObjectId("541c035f9c3009e80de19d6c"), "ts" : 1411122016, "close" : false, "users" : [ "7e8f5f8fc847bc6", "a285496ba35fe98" ], "__v" : 0 } /* 2 */ { "_id" : ObjectId("541c035f9c3009e80de19d6d"), "ts" : 1411122016, "close" : false, "users" : [ "7e8f5f8fc847bc6", "c2f1f4e949237d1" ], "__v" : 0 } This is a collection of conversations.
Suppose my id is 7e8f5f8fc847bc6 .
I need to create a new dialog with user id - c2f1f4e949237d1 .
For this I need to check on the existence of such a dialogue.
If it already exists and close: false, then you need to display its dialog id, if not, create a new one.
The problem is that I do not understand how to make a verification request in mongoose.
In the users array, data can be in any order , but there can be no more than two.
In sql, it’s something like this:
select ... where (users = ['c2f1f4e949237d1', '7e8f5f8fc847bc6'] or users = ['7e8f5f8fc847bc6', 'c2f1f4e949237d1']) and close = false