Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1242

Adding database name as property of Collection

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 3.0.2
    • Affects Version/s: 3.0.1
    • Component/s: Native
    • None

      I'm working with Change Streams which requires the database name and collection name in the pipeline and it would be ideal to have the database name available directly on the Collection so I can just pass the collection to any functions that work with change streams, without having to use split on the namespace property of Collection.

      Here is code that could be a little cleaner if database were a property of Collection

      findFlights(coll, origin, dest, date, function(results) {
      		watchFlights(coll, origin, dest, date, results);
      		assert.equal(err, null);
      		//client.close()
      	});
      
      	//watch flights that free up inventory
      	const pipeline = [
      		{$match:
      			{
      				"operationType": "replace",			//could also look for 'update' for individual field changes
      				ns: {db: "airlines", coll: "flightInventory"},
      				"documentKey._id": {$in: unavailList},
      				"fullDocument.seatsAvail": {$gt: 0}
      			}
      		}
      	];
      	const changeStream = coll.watch(pipeline, {fullDocument: "updateLookup"});
      
      	changeStream.on("change", function(addedSeats) {
      		console.log(addedSeats);
      	});
      

      I have to either pass the Collection and split it in each function I call, or I have to pass the Collection, dbName, and collName to each function, which feels a little unnecessary when I theoretically can get the dbName from the Collection object

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            matt.kalan@mongodb.com Matt Kalan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: