mongodb - Find a Document where value matched in either field using Mongoose Middleware -


i have list of account connections between source , target accounts schema looks like

var connectionrequestschema = new schema({   sourceaccountid: {     type: schema.objectid,     ref: 'account'   },    targetaccountid: {     type: schema.objectid,     ref: 'account'   },    status: {     type: string,     enum: ['pending', 'accept', 'decline'],     trim: true   } }); 

i want query documents sourceaccountid or targetaccountid equal queried accountid.

i saw link how-to-find-a-document-where-either-one-or-another-field-matches-a-value relevant find docouments using stand find method in mongo.

user.findone({   $or: [       {first_name: name},       {last_name: name},   ], }, function(err, user) {   }) 

but using mongoose middleware , i'm not sure how construct condition.

already find solution , write

connectionrequest.find({   $or: [       {sourceaccountid: "5736eac90a39c2547cb9d911"},       {targetaccountid: "5736eac90a39c2547cb9d911"},   ], }, function(err, connection) { console.log(connection)   }) 

finally got array of documents


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -