如何使用graphql从mongodb查询日期?
我正在尝试按日期时间查找文档 我有以下mongo文件样本:如何使用graphql从mongodb查询日期?,mongodb,mongoose,graphql,Mongodb,Mongoose,Graphql,我正在尝试按日期时间查找文档 我有以下mongo文件样本: { "_id" : ObjectId("5df8ea55ac02282c15917e46"), "title" : "Bán gấp căn 01 DT 62m2 căn góc, giá 1,05 tỷ. LH C Nga 0979441985", "address" : "La Khê - Hà Đông", "avatar" : "https://file4.batdongsan.com.vn/cr
{
"_id" : ObjectId("5df8ea55ac02282c15917e46"),
"title" : "Bán gấp căn 01 DT 62m2 căn góc, giá 1,05 tỷ. LH C Nga 0979441985",
"address" : "La Khê - Hà Đông",
"avatar" : "https://file4.batdongsan.com.vn/crop/200x200/2019/12/07/20191207173723-31f3_wm.jpg",
"price" : "1.05 Tỷ",
"lat" : 20.9719924926758,
"lon" : 105.756340026855,
"id" : 15504225,
"area" : "62 m²",
"cat" : "Bán căn hộ chung cư",
"date" : "17/12/2019",
"room" : 2,
"DateTime" : ISODate("2019-12-17T22:00:36.136+08:00")
}
我定义了一个模式:
const sellType = new GraphQLObjectType({
name:'Sell',
fields: () => ({
_id:{type:GraphQLString},
id:{type:GraphQLString},
title:{type:GraphQLString},
address:{type:GraphQLString},
avatar:{type:GraphQLString},
price:{type:GraphQLString},
DateTime:{type:GraphQLDateTime}
})
})
我还定义了根查询:
const RootQuery = new GraphQLObjectType({
name:'RootQueryType',
fields: {
property_for_sell_by_datetime:{
type: sellType,
args:{DateTime:{type:GraphQLDateTime}},
resolve(parent, args){
return sell.find({DateTime:new Date(args.DateTime)})
}
}
}
})
但我不知道为什么我找不到任何文件使用:
{
property_for_sell_by_datetime(DateTime:"2019-12-17T14:00:36.136Z"){
_id
DateTime
}
}
编辑:
我厌倦了使用findOne
。它起作用了。但是find
不起作用
编辑2:
我需要将类型定义为GraphQLList以使用find而不是findOne,我需要将类型定义为GraphQLList要使用find而不是findOne,我需要将类型定义为GraphQLList我尝试使用findOne。它起作用了。但是为什么?我试着用芬顿。它起作用了。但是为什么呢?