[GODRIVER-1201] How do we combine filters with the driver? Created: 17/Jul/19 Updated: 27/Oct/23 Resolved: 05/Sep/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON, CRUD |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Maxime Guittet | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Using MAC OS X, Goland |
||
| Description |
|
Hey folks
I am trying to combine some filters with no success, can someone help me out? ``` // FindOneByID returns an error on fail, otherwise, it sets the {out} by the result.func FindOneByID(collectionName string, id *primitive.ObjectID, out interface{}, considerArchivedItems bool) error { ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) var filter bson.M } else { filter = bson.M{"$and": bson.A{ bson.M {"_id": id}, bson.M{isArchived: bson.M{"$ne": false}}}} } ``` Now, I insert an object as archived and trying to get the document. The document is inserted as archived, so I want to consider archived items. ``` const ( databaseNameUnitTests = "database_name_unit_tests" databaseCollectionNameUnitTests = "database_name_unit_tests") ``` The following query from Robo 3T : `db.getCollection('database_name_unit_tests').find({$and:[ {"_id":ObjectId("5d2e8afeb0e106fbe0d5af21")},{"is_archived": {$ne:false}}]})`this works tho, where am I wrong? |
| Comments |
| Comment by Divjot Arora (Inactive) [ 12/Aug/19 ] |
|
Hi maxime.guittet@say-eyes.com, The $and filter looks fine to me, but there's a lot of code here. Can you try to create a minimal example that reproduces this issue? |