简体   繁体   English

MongoDB(带C#驱动程序),有没有日志?

[英]MongoDB (with C# driver), is there any log?

I'd like to know if there're any log when you try for example to insert something into field Name of document Customer. 我想知道是否有任何是日志当您尝试例如插入东西放到文档客户的字段 But the field Name has been renamed in the mongodb for FirstName ? 但字段名称已在mongodb中重命名为FirstName

Because I just tried something like that, I renamed every field's name called Name into FirstName of my collection of Customer document. 因为我刚尝试了类似的东西,所以我将名为Name的每个字段名称重命名为我的Customer文档集合的FirstName And in my C# code, I have a query which used to work, it removes a customer with Name "John". 在我的C#代码中,我有一个过去常用的查询,它删除了名为“John”的客户。 I execute it, the query runs without errors but nothing happens in the database. 我执行它,查询运行没有错误,但数据库中没有任何反应。 It should tell me that field Name doesn't exist anymore. 它应该告诉我字段名称不再存在。 How do you detect that ? 你怎么发现的?

Thanks. 谢谢。 John 约翰

[EDIT] my C# code: [编辑]我的C#代码:

public void DeleteOverride(Guid applicationId, string settingKey, string name)
{
   var query = Query.And(Query.EQ("_id", applicationId), Query.EQ("Settings.Key", settingKey));
   var update = Update.Pull("Settings.$.Overrides", new BsonDocument {{"Name", name}});
   Run(database => database.GetCollection<ApplicationViewModel>("Applications").Update(query, update));
 }

Here's in my example: the field Name has been renamed for DefinedFor in the dababase for every documents of my collection Application, I run it, and no exceptions has been thrown. 这是在我的示例中:字段Name已在dababase中为我的集合Application的每个文档重命名为DefinedFor ,我运行它,并且没有抛出任何异常。 My visual studio has CLR exceptions enabled. 我的visual studio启用了CLR例外。

There is not such log. 没有这样的日志。 You should care about fields renaming yourself. 您应该关心自己重命名的字段。

You can write unit test for each update to make sure that updates work correctly and detect problems with renames. 您可以为每个更新编写单元测试,以确保更新正常工作并检测重命名问题。

I guess string names in queries/updates is the weakest side of the official driver. 我猜查询/更新中的字符串名称是官方驱动程序中最薄弱的一面。

MongoDB is a schema free database so there is no such thing as a "field no longer exists" error. MongoDB是一个无架构的数据库,因此不存在“字段不再存在”错误。 Any field may or may not exist, so its absence is not an error. 任何字段可能存在也可能不存在,因此它的缺失不是错误。

A future version of the C# driver will support LINQ, which will catch some errors at compile time, and will also handle the mapping from the C# property name to the BSON element name, which should help avoid most mismatches. 未来版本的C#驱动程序将支持LINQ,它将在编译时捕获一些错误,并且还将处理从C#属性名称到BSON元素名称的映射,这应该有助于避免大多数不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM