SmartCollection in Meteor generating unpredictable outcomes

When executing News.insert({name: 'Test'}) in the browser JS console, it caused {{count}} to increase from 0 to 1.

Checking in mongo console using mrt mongo, db.news.find().count() also returns 1. However, after adding a record through the mongo console with

db.news.insert({name: 'TestAgain'})
, {{count}} stays at 1 while in mongo, there are now 2 records.

Question: What is causing such inconsistency between minimongo and the mongodb console?

If I switch Meteor.SmartCollection to Meteor.Collection and refresh the page, {{count}} becomes

2</code. But reverting back to <code>Meteor.SmartCollection
sets {{count}} back to 1!

collections/news.js

News = new Meteor.SmartCollection('news');

client/views/main.html

<template name="news">
    {{ count }}
</template>

client/views/main.js

Template.news.count = function() {
    return News.find().count();
}

Using Meteor v6.6.3 with SmartCollection v0.3.2.2


Update

Following Cuberto's recommendation, Oplog has been enabled on my Mongodb server.

export MONGO_URL=mongodb://192.168.1.111:27017/myDb
export OPLOG_URL=mongodb://192.168.1.111:27017/local
mrt

mongod is running with --replSet meteor and mongodb was set up as follows:

var config = {_id: "meteor", members: [{_id: 0, host: "127.0.0.1:27017"}]}
rs.initiate(config)

The prompt in mongo changes to meteor:PRIMARY> and db.local. indeed contains the collection oplog.rs.

Upon starting meteor, the console displays

SmartCollection charged with MongoDB Oplog
.

Problem: Despite this setup, when trying to do News.find() in the browser JS console, no results are retrieved. Yet, the same query in the mongo client yields the correct result. Switching from Meteor.SmartCollection back to Meteor.Collection resolves the issue.

How can we effectively troubleshoot the problem with SmartCollection?

Answer №1

Ensure your MongoDB is properly configured to utilize oplog and set the necessary environment variables following the instructions provided in this link:

With smart collections eliminating the need for periodic database polls, it's essential to have an oplog-enabled mongodb instance in order for it to detect changes within the database made from sources outside of meteor.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Removing a single object from an array of objects using MongooseJS

Hello to all the MongooseJS experts out there! I'm a newcomer to MongooseJS, and I've been trying to solve this problem for the past two days but haven't found a solution yet. Thank you in advance for any help! The Issue with My Delete me ...

Different Line Thickness in Dropdown Menu

Is there a way to adjust line heights in CSS within a drop down menu? I have attempted to change the font sizes of each element, but the new font size does not seem to take effect once an option is selected. Any suggestions would be greatly appreciated! & ...

Issue: [$injector:unpr] Provider not found: RequestsServiceProvider <- RequestsServiceFor more information on this error, please visit the website: http://errors.angularjs.org

Despite defining my service name in all necessary places, I am still encountering the error mentioned above. Below is my app.js: var app = angular.module('ionicApp', [ 'ionic', 'ngCordova', 'checklist-model' ]) ...

The NestJs project fails to display the updates when using the "tsc" command before running either "npm run start" or "npm run start:dev"

As a beginner in nestjs, I decided to start a tutorial to learn more about it. However, whenever I make updates or changes to my code, I don't see any changes reflected in the results. Can someone please assist me with this issue? Below are my tsconfi ...

Defining the signature of an unnamed function in TypeScript

Within my Express code, I have an anonymous function set up like this: app.use((err, req, res, next) => { // ... }); I am looking to specify the type of the function as ErrorRequestHandler (not the return type). One way to achieve this is by defining ...

Sharing $scope Data Between Controller and Directive in AngularJS

Recently, I created a straightforward directive that displays an object: var app = angular.module("myApp", []); app.controller('myCtrl', function($scope) { $scope.users=[ {name:'davidi',age:'23'}, {name:'karen ...

What is the most effective method for transferring data to a concealed input field?

I currently have a webpage with dual forms - one on the main page and another within a Bootstrap modal. The primary form includes fields like "Neck, Chest, Waist," while the modal's form only has an email field. To streamline the submission process, ...

Calculate the occurrences of numbers within a string in an array of objects containing a specific string each time an object is removed

I am facing an issue where I need to re-number strings based on their type, regardless of their previous number. For example, if I delete Oranges 2 from [Oranges 1, Oranges 2, Oranges 3], it should become [Oranges 1, Oranges 2]. This means the numbers shou ...

How to choose `optgroup` in Vue 1.x

In previous iterations of vue.js, developers had the ability to generate a dynamic select list utilizing optgroups similar to the example found here. In the latest versions of vue, the documentation suggests using v-for within the options instead of optgr ...

When utilizing the async module in Node.js for a MongoDB query, it is important to note that a callback is not required

Trying to implement a function exported from another file within an async each loop, which iterates through an array of incoming data and runs queries accordingly: const query = require('./queries') function processRequest(req, resp, doneFun ...

Avoiding console errors when a REST call fails

After conducting some research, it appears that achieving this is not possible. Therefore, I decided to seek advice. My current task involves making a REST GET call to check for the existence of a folder. If the folder does not exist, I create a new one; ...

Identify and track colored dots within an image using tracking.js

I'm working on creating a program that can tally the number of dots on dominoes in an image, such as the one shown here: https://i.sstatic.net/NKHXl.jpg My goal is to develop this functionality using JavaScript. I've attempted to learn how to u ...

Tips for setting up a Vue.js property as an array type element

To begin, I am looking to initialize the properties of image, description, video, and title with the corresponding fields from the first element in the variants array. The variants array is retrieved by sending an AJAX request that returns a JSON file. ...

Tips for securing firebase-admin credentials in Next Js

I've encountered a challenge while using firebase-admin in Next Js. I attempted to hide the firebase service account keys using environment variables, but ran into an issue because they are not defined in server-side on Next JS. As a workaround, I had ...

What's the Secret Behind the Mysterious Parameter in setState?

Currently enrolled in a TypeScript + React course where I am working on developing a todo list application. However, my query is related to a specific feature of React. Within the function for adding a new Todo item, there is a statement declaring a funct ...

problem with passing the identification number into the function

I am facing an issue with passing the id into a javascript onClick method. I am using the Spring framework and in the controller class, I send the related id to the JSP file like this: model.addAttribute("uploadid", uploadid); Afterwards, I need to p ...

Maintaining Existing Filters and Incorporating Additional Filters in React/Next.js Data Filtering

I'm currently facing a challenge with filtering data in React/Next.js. The issue I'm encountering is that whenever I set a new filter, the previous filters get removed. For instance, if a user performs a search, it works fine but the tag filters ...

Javascript promises executing in a mixed-up sequence

Utilizing Javascript's native Promise, I created a modified version of fs.readFile called readFileAsync. This function reads and parses a JSON file, returning the object when resolving. function readFileAsync(file, options) { return new Promise(fun ...

It is not possible to include parameters in mongoose schema that have not been defined

Is it possible to add new parameters in a MongoDB collection that are not defined in the Mongoose schema? Below is the current schema: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UsersSchema = new Schema({ FirstNam ...

What steps should I take to resolve the issue with this error message: Error: listen EADDRINUSE

How can I resolve the following issue? system: gulp npm windows issue: ... Oh no. Encountered error listen EADDRINUSE 127.0.0.1:35729 ... Error: listen EADDRINUSE 127.0.0.1:35729 at Object._errnoException (util.js:1021:11) at _exce ...