Meteor doesn’t use Mongo views. Basically you only use find(). You instead create your views in Blaze or React, using template helpers and such. Download the demo apps and have a look at how they’re made.
rawCollection is useful for running commands on a collection that already exists. Views, however, are computed on demand during read operations and have to be created in advance. The syntax is db.createView(<view>, <source>, <pipeline>, <collation>). Alternatively, a view can be created using db.createCollection.
// Use a collection that already exists that you're already using
const SomeCollection = new Mongo.Collection('some_collection');
// Then grab the raw db handler
// @link http://mongodb.github.io/node-mongodb-native/2.2/api/Db.html
const db = SomeCollection.rawDatabase();
// Unfortunately, this driver doesn't support the `db.createView` method
// So let's use `db.createCollection` instead
// @link https://docs.mongodb.com/manual/reference/method/db.createCollection/#db.createCollection
db.createCollection('orderView', { // name of the view to create
viewOn: 'order', // name of source collection from which to create the view
pipeline: [{
$lookup: {
from: 'customer',
localField: 'customerId',
foreignField: '_id',
as: 'customerDoc',
} }, { $unwind: '$customerDoc' }
],
});
Hi guys, did anyone use Mongo View in Subscriptions?
We query Mongo View in publication and use .observeChanges() to publish results. For some reason, after 3-5 seconds all the documents got removed from minimongo as result of ‘removed’ event fired. Did anyone experience anything similar?