findOne

findOne(query, options, callback){Promise}

lib/collection.jsline 1070

Fetches the first document that matches the query

Name Type Description
query object

Query for find Operation

options object optional

Optional settings.

Name Type Default Description
limit number 0 optional

Sets the limit of documents returned in the query.

sort array | object   optional

Set to sort the documents coming back from the query. Array of indexes, [['a', 1]] etc.

projection object   optional

The fields to return in the query. Object of fields to include or exclude (not both), {'a':1}

fields object   optional

Deprecated Use options.projection instead

skip number 0 optional

Set to skip N documents ahead in your query (useful for pagination).

hint Object   optional

Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}

explain boolean false optional

Explain the query instead of returning the data.

snapshot boolean false optional

DEPRECATED: Snapshot query.

timeout boolean false optional

Specify if the cursor can timeout.

tailable boolean false optional

Specify if the cursor is tailable.

batchSize number 1 optional

Set the batchSize for the getMoreCommand when iterating over the query results.

returnKey boolean false optional

Only return the index key.

maxScan number   optional

DEPRECATED: Limit the number of items to scan.

min number   optional

Set index bounds.

max number   optional

Set index bounds.

showDiskLoc boolean false optional

Show disk location of results.

comment string   optional

You can put a $comment field on a query to make looking in the profiler logs simpler.

raw boolean false optional

Return document results as raw BSON buffers.

promoteLongs boolean true optional

Promotes Long values to number if they fit inside the 53 bits resolution.

promoteValues boolean true optional

Promotes BSON values to native types where possible, set to false to only receive wrapper types.

promoteBuffers boolean false optional

Promotes Binary BSON values to native Node Buffers.

readPreference ReadPreference | string   optional

The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).

partial boolean false optional

Specify if the cursor should return partial results when querying against a sharded system

maxTimeMS number   optional

Number of milliseconds to wait before aborting the query.

collation object   optional

Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).

session ClientSession   optional

optional session to use for this operation

callback Collection~resultCallback optional

The command result callback

Returns:

Promise if no callback passed

上一篇:auto.js实现微信双向删除好友功能(检测僵尸粉)


下一篇:billu b0x