-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_mongo_index.js
More file actions
32 lines (29 loc) · 1.02 KB
/
m_mongo_index.js
File metadata and controls
32 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Created by 枯荣<[email protected]> on 2018-12-09 22:53.
*/
const logger = require( "../lib/logger" );
const mongoose = require( "mongoose" );
const schema = new mongoose.Schema( {
title: { type: String },
soure: { type: String },
thumb: { type: String },
author: {type: String},
updateAt: {type: Date},
createAt: {type: Date}
}, {
collection: "book"
} );
mongoose.connect( "mongodb://localhost:27017/mobius_self", ( err ) => {
if (err) {
logger.error( "connect failed" );
} else {
logger.done( "connect success" );
}
} );
const bookModel = mongoose.model( "book", schema );
// bookModel.findOne( { title: "你不知道的 JavaScript(下)" } ).exec((err,result)=>{
// console.log(result)
// });
bookModel.find( { title: /JavaScript/ } ).where( "title" ).in( [ "你不知道的 JavaScript(上)", "你不知道的 JavaScript(中)", "你不知道的 JavaScript(下)" ] ).select( "author, updateAt, createAt" ).limit( 200 ).sort( { author: -1 } ).exec( ( err, result ) => {
console.log( result );
} );