我正在使用mongodb,我以这种方式将datetime存储在我的数据库中
约会"17-11-2011 18:00"我存储:
date = datetime.datetime(2011, 11, 17, 18, 0)
db.mydatabase.mycollection.insert({"date" : date})
Run Code Online (Sandbox Code Playgroud)
我想做这样的请求
month = 11
db.mydatabase.mycollection.find({"date.month" : month})
Run Code Online (Sandbox Code Playgroud)
要么
day = 17
db.mydatabase.mycollection.find({"date.day" : day})
Run Code Online (Sandbox Code Playgroud)
谁知道怎么做这个查询?
我正在用nodejs构建一个房间预订系统。目前我有hotels,rooms和bookings作为收藏。
rooms被引用hotels和bookings被引用rooms。
预订.js
const bookingSchema = new mongoose.Schema({
room: {
type: mongoose.Schema.Types.ObjectId,
ref: 'rooms'
},
start: Date,
end: Date
});
Run Code Online (Sandbox Code Playgroud)
房间.js
const roomSchema = new mongoose.Schema({
roomid: String,
hotel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'hotel_managers'
},
type: String,
price: Number,
capacity: Number,
facilities: [String],
amenities: [String],
img: [String]
});
Run Code Online (Sandbox Code Playgroud)
酒店.js
const hotel_manager_schema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true
},
password: {
type: String, …Run Code Online (Sandbox Code Playgroud)