This is the official documentation page for weiv-data APIs powered by ExWeiv Apps, we have built an API library for you to use with your Wix sites. This package is designed to work in Wix websites with Velo and JS and mainly focused to developers not basic users but anyone can use it for free! Before we start here are the advantages and disadvantages of weiv-data when compared to wix-data.
Feature | weiv-data (M0 Cluster) | wix-data (Basic Plan) |
---|---|---|
Database Type | NoSQL - MongoDB | NoSQL - MongoDB |
Frontend Support | Only Backend | Frontend Supported |
Performance/Speed | 8.5/10 | 6.5/10 |
Cold Start Time | Extra 1000-1500ms | No Cold Start |
Scalability (General) | Very High | Moderate |
Consistency | 8/10 | 9/10 |
Read Limits | 100/sec | 1500/min |
Write Limits | 100/sec | 100/min |
Request Timeout | 30sec/request | 5sec/request |
Index Limits | 3 Index in Total | 1 Index in Total |
Collection Limit | 500 Collections | 15 Collections |
Database Limit | 100 Databases | 1 Database (Auto Generated) |
Storage Limit | 512MB | 1500 Items/Rows |
Item Size Limit | 16MB | 512KB |
Automatic Backup | No Automatic Backup | 1 Per Month |
Manual Backup | Yes | Yes |
Visual Dashboard | Yes (Not Integrated to Wix) | Yes (Also Integrated with Wix) |
Datasets (Connecting Data Visually) | Not Available | Available |
Pricing | Free, Monthly, Hourly | Free, Monthly (Starting from 12€/m) |
Multicloud | No | Yes |
RAM | Shared RAM | 400MB (1 Micro Container) |
CPU | Shared vCPU | 1vCPU (1 Micro Container) |
Security | Very Good | Much More Better |
In MongoDB M0 Cluster you WON'T have 100/sec limit for each class of operation you have 100/sec for any class of operation. So read/write/update/delete... sahres the same limit of 100/sec which is 6000/min
We have compared the limits and other things based on the lowest leves. M0 Cluster for MongoDB (Free) and Basic Plan for Wix Studio (12€/m).
There are still more things we can consider between each library and don't forget that our library is not a platform it's just converting mongodb into similar syntax and adding some features top of it so you can code like in wix-data using weiv-data. What this means is we are actually comparing MongoDB Atlas and wix-data.
And when you have the freedom of upgrading your own MongoDB clusters it's very hard for wix-data to be better because you can upgrade to highest level of dedicated cluster and probably your setup will be better.
But when we compare the lowest levels in each platform you can see that there some cons and pros. Remember there is no one size fits all so consider your app/website and decide which library to use. If you don't need speed and if you are building something simple there is no need to use weiv-data in general. But if you are building something more complex and that needs speed than you can go with weiv-data.
Also keep in mind that we didn't list every single detail about each library/platform we recommend you to take a look at MongoDB M0 Cluster limits and Wix Studio Basic plan limits to let you even understand better the limits and features.
When we have test the M0 Cluster it was quite well for begining if your application is not expecting a lot of users you can just start with free version which is M0 then you can upgrade to M2 or M5 or even to a dedicated clusters which is M10 or higher you can also enable multi-cloud and auto-scale features in dedicated clusters.
So we think it's okay to start with M0 and then upgrade if there is a need for an upgrade. Monitor your functions using Wix Monitoring tools and see if you really need a higher version.
Before upgrading directly remember you can optimize your code and collections using related features such as indexes.
Let's start by setting up our environment for weiv-data and make things ready. Follow the steps and you will be ready to go in 1-3mins:
If you haven't created a MongoDB account yet go ahead and create one!
Custom Roles
tab and create three different roles: Admin
, Member
and Visitor
.Database Users
tab and create three different users.Network Access
page from the MongoDB dashboard.IP Access List
tab.Allow Access From Anywhere
. In this way Wix servers will be able to access your database (also any other server).Developer Tools -> Secrets Manager
WeivDataURIs
.{
"visitor": "<visitor-uri>",
"member": "<member-uri>",
"admin": "<admin-uri>"
}
WeivOwnerID
. This collection will be used to get visitor ids when you enable it for each operation.weiv-data
library.Packages & Apps
. You will see npm click +
button. And search for "@exweiv".@exweiv/weiv-data
npm package install that package.mongodb
package since you will deal with ObjectIDs
.import { ObjectId } from 'mongodb';
. (More examples below and can only be used in backend).Public & Backend
section.WeivData
in your backend section of your site.connection-options.js
and data.js
. These are required even if you don't set any data hooks or custom connection options.Even if you won't setup any custom connection settings or data hooks create WeivData
folder in your backend and create two .js files data.js
and connection-options.js
. This is important and must have to let library work.`
We also explain how you use X.509 instead of username and password authentication method.
Click to connect button in your cluster.
Then you will see an example of connection uri/string.
const username = "Admin";
const password = "StrongPassword.26.34.61";
// Replace username, password and rest of the URL with your own!
const uriExample = `mongodb+srv://${username}:${password}@testingcluster.luecqd2.mongodb.net/`;
Currently we don't have any tutorial about how you can setup IP Address within Wix. Instead we allow any IP address and use strong passwords. We are working on different type of authentication methods that's available in MongoDB and also possible with Wix.
In weiv-data unlike wix-data we don't use string based item ids. Instead we use ObjectId
based item ids. We use ObjectId for better speed and performance. You can learn more about ObjectId via a magical tool called Google
, Gemini
, Chat-GPT
etc. 😊
Currently we are optimizing our code to return ObjectID in every case right now in some cases our library returns string instead of ObjectID. (This will be fixed asap.)
Note: You can use a custom function in our library to convert strings into ObjectId or ObjectIds to string.
import { idConverter } from "@exweiv/weiv-data";
const stringId = "...";
const objectId = "...";
idConverter(stringId); // returns objectid
idConverter(objectId); // returns stringid
Here is a direct example for advanced users to let them understand it directly.
Example shows a path but you can also use buffer data with
key
field in options. See MongoDB docs for more.
// In your `backend/WeivData/connection-options.js` file.
const defaultOptions = () => {
return {
maxPoolSize: 50,
minPoolSize: 5,
maxIdleTimeMS: 30000,
tls: true,
authMechanism: "MONGODB-X509",
};
};
// Defined as a function (can be async)
export const adminClientOptions = () => {
return {
...defaultOptions(),
tlsCertificateKeyFile: "../../../../../../../../../user-code/backend/WeivData/admin.pem",
};
};
// Defined as a function (can be async)
export const memberClientOptions = () => {
return {
...defaultOptions(),
tlsCertificateKeyFile: "../../../../../../../../../user-code/backend/WeivData/member.pem",
};
};
// Defined as a function (can be async)
export const visitorClientOptions = () => {
return {
...defaultOptions(),
tlsCertificateKeyFile: "../../../../../../../../../user-code/backend/WeivData/visitor.pem",
};
};
Let's talk about how it works. Basically you can create three different client options for each role and export them named as above example. And export them in that js file.
adminClientOptions
function will be used for admins. memberClientOptions
function will be used for members. visitorClientOptions
function will be used for visitors.
In this way you can assign different certificates or options for each role.
If you don't create only one or two of these options defaults will be used for the one/s you didn't specify.
More About Connection Options in MongoDB
You can still use username and password method (SCRAM) which will be fine if you have strong passwords but if you want to use X.509 here is how. Username and password method (SCRAM) is easier and secure. Just create strong passwords!
Let us explain how does weiv-data works when connecting to clusters so you can better understand which options you can use for authentication.
You can also check our GitHub so you can understand how it works even create pull requests.
MongoClientOptions
) we use a JS file you create in your Wix backend. As we explain above.In this way you can manage connection uris/strings as well as connection options.
If you want to create users thats using X.509 method follow the steps:
certificate
option above.connection-options.js
file assign the path of file. (Read below)When you are pasting the path of .pem file in your backend use the following directory as reference:
const pathToBackend = "../../../../../../../../../user-code/backend/";
This is the path to your Wix backend. Yes it's different than what you have in your codes. But this one is the working one. Use this path to access your backend folder. You can also check the example code above.
You can probably also access to other folders like public, pages etc. Just let you know not needed for our library.
You can also use Buffer data of your .pem files which is probably what you'll prefer in production. You can store your .pem files in cloud providers and get signed URLs after that you can use that signed URLs to create a Buffer data via axios. And then you can use that Buffer data for X.509 method.
Using hooks in weiv-data and wix-data has similar way. We are currently not providing a hook for errors. But rest of the hooks are available like in wix-data. To create a hook you need to create a folder in your backend named WeivData
and then you also need to create a .js file (.js file now .jsw or .web.js) inside of that folder.
-> backend/WeivData/data.js
Then you will create your hooks as functions like in wix-data. Here is an example for afterGet hook:
// In backend/WeivData/data.js file
export async function dbname_collectionname_afterGet(item, context) {
if (item.number > 5) {
return true;
} else {
return false;
}
}
You need to name your functions correctly to let hooks work. The syntax is like that:
<database-name>_<collection-name>_<hook-name>
Both database name and collection name should be all lowercase.
If you want to use automatic pool management do not set min or max pool size in your custom connection options. In this way it will be handled by MongoDB driver and weiv-data library won't connect to cluster manually instead it will return a not connected MongoClient and driver will handle the connection when an operation starts.
If you want to manually configure it you can set min or max (or both) pool size in custom connection options. In this way our library will call the .connect method and it will return a connected client when performing operations.
MongoClients are cached and saved so after cold start it will be cached for 5 min. (Wix Container Time)
Ask for help, give feedback or anything else? info@apps.exweiv.com