Skip to content

Instantly share code, notes, and snippets.

@Miniwe
Created April 22, 2015 16:08
Show Gist options
  • Save Miniwe/18a62b00f3cd94dee993 to your computer and use it in GitHub Desktop.
Save Miniwe/18a62b00f3cd94dee993 to your computer and use it in GitHub Desktop.

Revisions

  1. Miniwe created this gist Apr 22, 2015.
    9 changes: 9 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    var ObjectId = require('mongoose').Types.ObjectId;
    var objId = new ObjectId( (param.length < 12) ? "123456789012" : param );
    // You should make string 'param' as ObjectId type. To avoid exception,
    // the 'param' must consist of more than 12 characters.

    User.find( { $or:[ {'_id':objId}, {'name':param}, {'nickname':param} ]},
    function(err,docs){
    if(!err) res.send(docs);
    });