NextJS, MongoDB Realm, Apollo Example? - mongodb

Our project which we actually developed in ReactJS, we are currently moving to NextJS.
Now we have the problem that our original method in ReactJS using MongoDB Realm and Apollo(GraphQL) to retrieve data does not work in NextJS due to the need of SSG and SSR.
After a long time of trying and searching for examples and introductions, we unfortunately haven’t found a solution yet. Now the question: Has anyone already done this or an example project that builds on NextJS, MongoDB Realm and Apollo(GraphQL)?
In case of need we can also use the SWR library. But we haven’t found any helpful (including SSG and SSR) and official examples explicitly for Realm.

Related

how to push firestore data to algolia Swift

I've been doing research for the last several hours finding out how to do full text search in iOS apps with Firestore. I eventually realized full-text search is not supported. I read up on Algolia, watched tutorials, read articles and still don't see a way to push data from Firestore to Algolia in Swift. Can somebody guide me to a post or maybe add like a code snippet or something to show me how I can use this software? Thanks.
Algolia offers SWIFT API client
Swift API client is an open source, production-ready API wrapper that abstracts from the complexity of directly interfacing with the Algolia Search API
Basically to work with algolia using any API client, you have to do few things,
Install the algolia client
https://www.algolia.com/doc/api-client/getting-started/install/swift/?client=swift
Initialize the client with your application ID and KEY
https://www.algolia.com/doc/api-client/getting-started/instantiate-client-index/
Indexing your data & Setup searchable attributes
https://www.algolia.com/doc/api-client/methods/indexing/
https://www.algolia.com/doc/guides/managing-results/must-do/searchable-attributes/
Perform search
https://www.algolia.com/doc/api-reference/api-methods/search/
Many sub-actions available within these to improve your experience with Algolia. I recommend you to go through the docs fully.
Yes, there are few other ways available to work with algolia, like using cloud functions for indexing data into algolia and doing only search from your client. But as you specifically mentioned SWIFT the above references would help you to get started!

How do I query an external GraphQL endpoint in Gatsby JS?

I don't seen any clear way to query an outside GraphQL endpoint (i.e. https://somewebsite.com/graphql) for data. Has anyone else done this, and how did you do it?
I assume it requires you to build a custom plugin, but that seems overkill for such a simple need. I have searched the docs and this issue doesn't really ever get addressed. 🤔
In Gatsby V2 you don't need to create your own plugin.
What you need is a plugin called gatsby-source-graphql
gatsby-source-graphql uses schema stitching to combine the schema of a
third-party API with the Gatsby schema.
You can find more info here.
The answer is, as you mentioned, writing a new source plugin. This is how Gatsby gets the data into it's internal GraphQL structure to then query.
Plugins are, at their core, just additions to the gatsby-node, gatsby-browser, and gatsby-ssr files. So you could write the logic needed at the top of your gatsby-node file to avoid abstracting it out into it's own plugin.
If you're not so into writing plugins for gatsby, like me, have a look here.
It explains in detail how you query any graphQL server via the Gatsby sourceNode API and the use of graphql-request.
Helped me to get data for e.g. from graph.cool as well as GraphCMS.
The problem though is that you always have to write 2 different kinds of graphQL queries, as they are usually not compatible to Gatsby's relay style queries. But still easier than building a whole plugin.

Mongodb document versioning using spring data

I am using Spring Data in my Java application to connect to MongoDb and have a requirement around versioning the documents (basically storing the history).
It seems that its pretty straightforward in Ruby, if one uses Mongoid
I was wondering if spring data has something similar for Java. Or are you better of trying to implement your own.
Yes there is a very good feature in Spring data which is auditing you can refer to the following link
http://www.javacodegeeks.com/2013/11/auditing-entities-in-spring-data-mongodb-2.html
After lot of research I found that https://javers.org/documentation/spring-boot-integration/. This works like rock solid and very easy to implement.
This library helps to store all the history of the changed fields and easy to query over it and it has great support of it. The sample POC shared here: https://nullbeans.com/auditing-using-spring-boot-mongodb-and-javers/

Zend MongoDB implementation

I am attempting to integrate Zend with MongoDB. I think I am almost there, but I need some help to complete the task. I am new to both zend and mongo, but reasonably experienced with PHP and MySQL.
Some details:
My Zend project is based on the skeleton tutorial at http://framework.zend.com/manual/2.0/en/user-guide/skeleton-application.html. This works fine on my computer, but is mysql-based.
I have installed MongoDB. I can write nosql on the command line and I can instantiate a MongoClient object in a PHP script, so those things seem to work and talk to each other.
I want to use mongo instead of mysql, and I have implemented Doctrine. I have no idea what Doctrine does, and I've been through several searches to try and find how to run mongo commands in zend. These facts lead me to conclude that I don't know what I'm doing.
So to the specifics of my question:
As I understand it, I should be instantiating a mongo object somewhere. If so, where should I put the instantiation in zend?
If not, presumably I need an existing instantiation of the mongo object to run various find/save commands from inside the model class, so if that's true, how do I access the existing mongo object?
Thanks for any help, and clarification questions are equally welcome.
Edited 13/12/2012 for clarification.
With the given answers it seems I am on the right track, and I can further clarify what I need:
Looking at the Doctrine Documentation linked below, I am still unclear where the document manager instantiation is supposed to occur. I would have expected it to go into a more generic location which is run on every page load. Also, most of the tutorials I find seem to refer to a file structure different given from the skeleton application, so when they say to put certain things in certain places, I'm not sure where they mean. For example, I keep seeing references to bootstrap files, but my only bootstrap files are in test directories.
My questions are these:
What code do I need to add into the indexAction function (which definitely responds when I go to the correct URL) if I simply want to print_r all the documents in a collection?
Do I need to add any other code elsewhere, if so where, and what code?
These are the different bits and what they do, working from the bottom up:
mongodb: data persistance
doctrineODM: Object Document Mapper. This maps mongo documents to php objects. It means you don't have to worry about doing any calls against mongo directly - you just work with plain old php objects. To use doctrineODM you need to define your model classes, and get the hang of using the DocumentManager - suggested, the Doctrine docs are quite good.
doctrineMongoODMModule: A module that integrates doctrine with zf2. The main thing it does is allow you to configure doctrine using zf2 config style, and gives you access to the DocumentManager via the zf2 ServiceManager. (I does quite a few other things too, but they are the main ones)
zf2 (mvc): Lets you define an interface so other things (like a web client) can manipulate your documents.
There is brilliant module doctrine-mongo-odm-module for mongoDB access.
Just add to composer.json
"require": {
....
"doctrine/doctrine-mongo-odm-module": "dev-master",
....
Doctrine documentation should help how to use it.

Trying to DRY up nodejs express app using mongodb

I'm trying to separate my mongodb code in a nodejs express app and am having troubles understanding how to shuffle things around.
here's a gist of what I have
https://gist.github.com/759446
I've dumbed it down to almost nothing in the middleware.
When I start the server, res.myvar is correctly set to "object" in the first request. Every subsequent request fails with res.myvar being "undefined".
I just want to stick the db code in a single place and then be able to use it in my various routes. Am I going about this wrong? All the examples on the mongodb nodejs driver page just make db queries etc. I'm not finding much integrating the whole thing in an express app.
What I had originally was opening new db connections on every request.
I've edited the gist and left the old stuff commented out.
It works now.
Many thanks to Ciaran's blog post http://howtonode.org/express-mongodb
It's kinda old but still helped.
I am writing node-fourm, I have the same problem at beginning. There is a db folder and controller folder in node-fourm, they are seperated now, and I can define method for each collection now. Check the code for detail.
I wrote mongoskin to make it possible.