-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
Cause: Your document class doesn't have a property that maps to MongoDB's _id field.
Fix: Add an Id property with [BsonId]:
public class MyDocument
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string Name { get; set; }
}Possible causes:
-
Serialization mismatch — Your property names don't match the BSON field names. Use
[BsonElement("fieldName")]to map them. -
Wrong collection name — Check that you're querying the same collection you inserted into.
-
Filter doesn't match — Test with
FilterDefinition<T>.Emptyto verify documents exist, then narrow your filter.
Cause: The collection hasn't been registered or created yet.
Fix: Either insert a document (auto-creates the collection) or register it explicitly:
options.AddCollection<MyDoc>("myCollection");Possible causes:
-
BsonInt64 vs BsonInt32 — The driver renders
$limitand$skipasBsonInt64. Use.ToInt32()when comparing. -
$sumproduces BsonDouble — The$sumaccumulator producesBsonDoubleby default. Use.ToInt32()not.AsInt32. -
Missing
$unwind— If grouping on array fields, you may need$unwindfirst.
Possible causes:
-
Not calling
MoveNextAsync()— Change stream cursors are pull-based. -
Events fired before watch started — Start watching before performing operations.
Cause: The LINQ expression translates to an operator not supported by the emulator.
Fix: Use the builder API (Builders<T>.Filter / .Update) instead of LINQ for complex queries. Check Filter & Update Operators for supported operators.
Explanation: TTL eviction is lazy — documents are only removed when a query executes. This matches the behavior of real MongoDB where the TTL background thread runs every 60 seconds.
Fix: Query the collection to trigger eviction, or check that the TTL field contains a valid DateTime / BsonDateTime value.
Check:
- The index was created with
new CreateIndexOptions { Unique = true } - The index was created before inserting duplicate documents
- For sparse indexes, documents missing the indexed field are intentionally allowed
Explanation: MapReduce is deprecated in MongoDB 5.0+. Use the aggregation pipeline instead:
// Instead of MapReduce:
var results = await collection.Aggregate()
.Group(x => x.Category, g => new { Category = g.Key, Count = g.Count() })
.ToListAsync();- Known Limitations — Where behavior differs from real MongoDB
- Features — Supported features
Getting Started
Integration & Dependency Injection
Data Management
Reference
- Feature Comparison
- Features
- Filter & Update Operators
- Aggregation Pipeline
- LINQ Support
- API Reference
Help