【发布时间】:2016-06-21 17:41:56
【问题描述】:
monoDB 标签中有很多关于不同问题的问题,我看到也有一些 cmets 请求类似的数据。
所以提供了How To Ask a Good Question,但这与 MongoDB 无关。 有什么好的文件可以让我提出好的和有价值的问题吗?
【问题讨论】:
标签: mongodb
monoDB 标签中有很多关于不同问题的问题,我看到也有一些 cmets 请求类似的数据。
所以提供了How To Ask a Good Question,但这与 MongoDB 无关。 有什么好的文件可以让我提出好的和有价值的问题吗?
【问题讨论】:
标签: mongodb
这里有一些规则可以帮助您为 MongoDB 相关问题获得好的和有价值的答案。
请参阅下面的一些常见类别和步骤,这些类别和步骤有助于收集数据,从而帮助您更快地找到合适的答案。
基础 - 随着 mongoDB 的发展,一些很酷的功能在更高版本中可用 - 为避免混淆,请提供您当前的 mongo 版本,让我们知道这是独立系统、副本集还是分片环境
李>关于性能的问题:
db.collection.find({query}).explain("executionStats") - 这将提供一些关于查询、索引、聚合框架的统计信息:db.collection.aggregate([{pieplineDatausedToExecuteAggregation},{explain:true}])
数据操作 - 由于查询基于文档结构,请提供有效的文档转储(甚至多个)并确保 mocked 字段反映查询中的字段,有时在尝试构建查询时,我们会无法插入示例文档,因为它们的结构无效。此外,如果您希望在流程 p 的 ned 处获得特定结果 - 请附上预期示例。
副本集/分片问题 - 请添加 rs.config() / sh.status() 并删除主机数据(如果敏感)
如果您有特定于驱动程序/框架的问题 - 请显示已完成的操作以及您的问题所在。有时很难将查询从 mongo shell 语法转换为驱动程序/框架语法 - 所以如果你可以尝试在 mongoDB shell 中构建该查询 - 并运行示例 - 请将其添加到问题中。
回复:1
在 Windows 笔记本电脑上使用 mongo 2.6 我无法收集超过 2GB 的数据,为什么?
回复:2
我的查询db.collection.find({isValid:true})耗时超过30秒,请看解释输出:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "test.collectionName",
"indexFilterSet" : false,
"parsedQuery" : {},
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : []
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 6,
"executionTimeMillis" : 0,
"totalKeysExamined" : 0,
"totalDocsExamined" : 6,
"executionStages" : {
"stage" : "COLLSCAN",
"nReturned" : 6,
"executionTimeMillisEstimate" : 0,
"works" : 8,
"advanced" : 6,
"needTime" : 1,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 6
}
},
"serverInfo" : {
"host" : "greg",
"port" : 27017,
"version" : "3.3.6-229-ge533634",
"gitVersion" : "e533634d86aae9385d9bdd94e15d992c4c8de622"
},
"ok" : 1.0
}
回复:3
我无法从聚合管道 mongo 3.2.3 中的每条记录中获取最后 3 个数组元素
我的查询:db.collection.aggregate([{aggregation pipeline}])
文档架构:
{
"_id" : "john",
"items" : [{
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e4"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e5"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e6"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e7"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e8"),
"grad" : true
}
]
}
]
}
//expected result
{
"_id" : "john",
"items" : [{
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e4"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e5"),
"grad" : true
}
]
}, {
"name" : "John",
"items" : [{
"school" : ObjectId("56de35ab520fc05b2fa3d5e6"),
"grad" : true
}
]
}
]
}
回复:4
我的副本集有问题,数据未使用 mongo 3.2 复制到其他服务器,位于 rs.config 转储下方:
{
"_id" : "rs0",
"version" : 1,
"members" : [
{
"_id" : 1,
"host" : "mongodb0.example.net:27017"
}
]
}
回复:5
我在 mongo 中有聚合查询,无法从 c# 驱动程序中获取输入结果
startDate = new Date() // Current date
startDate.setDate(startDate.getDate() - 7) // Subtract 7 days
db.collection.aggregate([{
$match : {
LastUpdate : {
$gte : startDate
}
}
}, {
$sort : {
LastUpdate : -1
}
}, //sort data
{
$group : {
_id : "$Emp_ID",
documents : {
$push : "$$ROOT"
}
}
}, {
$project : {
_id : 1,
documents : {
$slice : ["$documents", 3]
}
}
}
])
我的 C# 代码
public static void Main()
{
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("test");
var collection = database.GetCollection<InnerDocument>("irpunch");
var aggregationDocument = collection.Aggregate()
.Match(x=>x.LastUpdate> DateTime.Now.AddDays(-40))
.SortByDescending(x => x.LastUpdate)
.Group(BsonDocument.Parse("{ _id:'$Emp_ID', documents:{ '$push':'$$ROOT'}}"))
// how to get projection result as typed object ??
.Project(BsonDocument.Parse("{ _id:1, documents:{ $slice:['$documents', 3]}}")).ToList();
}
}
【讨论】: