英文:
With 'someField': { $exists: true } Mongoose returns a document for which someField doesn't exist
问题
以下是代码部分的翻译:
for await (const expression of Expression.find({ 'definition': { $exists: true } })) {
console.log(Utils.stringize(expression))
}
你运行的 Typescript 代码出现了一些奇怪的情况。日志返回了下面的文档,其中字段 definition
不存在:
{
"_id": "63cc466d2c2338ef26205618",
"labels": [
"⊥"
],
"author": {
"userId": "63cc466c2c2338ef26205609",
"username": "webmaster"
},
"timestampCreation": "2023-01-21T20:09:17.027Z",
"tags": [
"native symbol",
"logic",
"mathematics",
"false"
],
"nbrViews": 1,
"nbrUsesInExpressions": 2,
"nbrUsesInTruths": 0,
"idsUsedExpressions": [],
"idsUsedExtraAxioms": [],
"type": {
"sort": "P"
},
"parameters": [],
"__v": 0
}
如果有所帮助,这是集合的 Mongoose 架构:
const expressionSchema = new Schema<IExpression>({
labels: {
required: true,
type: [String],
trim: true
},
author: {
type: Schema.Types.Mixed,
required: true,
},
timestampCreation: {
type: Date,
required: true,
},
tags: {
required: true,
type: [String],
trim: true
},
nbrViews: {
required: true,
type: Number,
},
nbrUsesInExpressions: {
required: true,
type: Number,
},
nbrUsesInTruths: {
required: true,
type: Number,
},
idsUsedExpressions: {
type: [Schema.Types.ObjectId],
},
idsUsedExtraAxioms: {
required: true,
type: [Schema.Types.ObjectId],
},
type: {
required: true,
type: Schema.Types.Mixed
},
parameters: {
type: Array
},
definition: {
type: Schema.Types.Mixed
},
idInstantiatedTruth: {
type: Schema.Types.ObjectId,
},
idResultingTruth: {
type: Schema.Types.ObjectId,
}
})
你已经尝试了 Expression.find({ 'definition': { $ne: null } })
和 Expression.find().where('definition').exists(true))
,还尝试了添加和删除一些引号,但结果仍然相同。
有人能理解这个问题吗?
英文:
Something strange is happening to me. I run the following Typescript code:
for await (const expression of Expression.find({'definiton': { $exists: true }}))
{
console.log(Utils.stringize(expression))
}
And the logging returns me the following document, in which the field definition
doesn't exist:
{
"_id": "63cc466d2c2338ef26205618",
"labels": [
"⊥"
],
"author": {
"userId": "63cc466c2c2338ef26205609",
"username": "webmaster"
},
"timestampCreation": "2023-01-21T20:09:17.027Z",
"tags": [
"native symbol",
"logic",
"mathematics",
"false"
],
"nbrViews": 1,
"nbrUsesInExpressions": 2,
"nbrUsesInTruths": 0,
"idsUsedExpressions": [],
"idsUsedExtraAxioms": [],
"type": {
"sort": "P"
},
"parameters": [],
"__v": 0
}
If it can be of some help, here is the Mongoose schema of the collection:
const expressionSchema = new Schema<IExpression>({
labels: {
required: true,
type: [String],
//unique: false,
trim: true
},
author: {
type: Schema.Types.Mixed, //Author,
required: true,
},
//timestampCreation: Date,
timestampCreation: {
type: Date,
required: true,
},
tags: {
required: true,
type: [String],
trim: true
},
nbrViews: {
required: true,
type: Number,
},
nbrUsesInExpressions: {
required: true,
type: Number,
},
nbrUsesInTruths: {
required: true,
type: Number,
},
idsUsedExpressions: {
type: [Schema.Types.ObjectId],
},
idsUsedExtraAxioms: {
required: true,
type: [Schema.Types.ObjectId],
},
type: {
required: true,
type: Schema.Types.Mixed //Sort|UnknownType|CompoundType
},
parameters: {
type: Array
},
definition: {
type: Schema.Types.Mixed //StatementBoundVariables,
},
idInstantiatedTruth: {
type: Schema.Types.ObjectId,
},
idResultingTruth: {
type: Schema.Types.ObjectId,
}
})
And I've tried with 'definiton': { $ne: null }
and Expression.find().where('definiton').exists(true))
, I've removed and added some quotes, but the result remains the same.
Anyone to understand this?
答案1
得分: 1
你对"definition"的拼写不一致。
在你的模式文件中,你正确地将其定义为"definition",但在你的示例查询中,你使用了"definiton"(请注意最后两个字符前缺少字母"i")。
英文:
Your spelling of 'definition' is inconsistent.
In your schema file you correctly define it as 'definition' but in your example query you use 'definiton' ( note the missing 'i' before the last two characters )
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论