问题
I would like of create a trigger where, to each subdocument inserted would increment in other collection a field, for generate a count of subdocuments that collection.
I tried create a search using MapReduce, but for Milions of the Registries is very slow.
Note: I use C#, but if you like show how to do in Bson, no problem.
Extructure my collection
public class Header
{
public Header()
{
Operation= new List<Operation>();
}
public ObjectId Id { get; set; }
public Int64 Code1 {get; set;}
public Int64 Code2 {get; set;}
public string Name { get; set; }
public List<Operation> Operations { get; set; }
}
public class Operation
{
public Operation()
{
Itens = new List<Item>();
}
public string Value { get; set; }
public List<Item> Item { get; set; }
}
public class Item
{
public string Value { get; set; }
}
回答1:
MongoDB has no triggers. You will have to implement this in your application by inserting the document and when the insert was successful, you use the $add operator to increment the field in the other document.
来源:https://stackoverflow.com/questions/25686744/how-to-create-trigger-in-mongodb