Absolute mongodb newbie here, and I must say I'm not impressed by the documentation. Anyway, my problem is I have a database on Mongodb Atlas, a Stitch application with a next.js frontend and trying to retrieve data like this:
import { setStitchClient } from '../utils/stitch';
export default class MyPage extends React.Component {
static async getInitialProps() {
const stitchClient = await setStitchClient();
const db = stitchClient.service('mongodb', 'mongodb-atlas').db('dbName');
await stitchClient.login();
const docs = await db
.collection('test')
.find()
.limit(200)
.execute();
return { docs: docs };
}
render() {...}
The test collection includes 150 documents imported with mongoimport cli. I verified the documents are correctly imported. However the .find()
above finds no records and the result is an empty array.
If I create a document through the frontend in another collection, I can find it without problems.
I guess there is no simple answer here but any hint would be highly appreciated. Thanks a lot!