mongo will read the .mongorc.js file from the home directory of the user invoking mongo. In the file, users can define variables, customize the mongo shell prompt, or update information that they would like updated every time they launch a shell.
here’s an example of ~/.mongorc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// use for query one doc only by id string
// input userId {string}
DBCollection.prototype.onedoc = function (userId) {
returnthis.findOne({"_id": ObjectId(userId)});
}
//use for query id with pipeline
//input userId {string}, pipeline {json object}
DBCollection.prototype.fid = function (userId, pipeline) {