MongoDB Setup for Mobile App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
MongoDB Setup for Mobile App
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1050
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Setting Up MongoDB for Mobile App

MongoDB in mobile context usually means Atlas — cloud MongoDB with built-in mobile capabilities: Atlas Device SDK (formerly Realm), Atlas Search, Atlas Data API. Direct MongoDB connection from mobile client through native driver — not practiced for same reasons as with PostgreSQL: credentials in code, no auth layer.

Two Usage Strategies

Strategy 1: MongoDB as Backend. Mobile client calls API (Node.js + Mongoose, or Atlas App Services), API works with MongoDB. Standard backend architecture.

Strategy 2: Atlas Device SDK (Realm) + Atlas Device Sync. Local Realm database on device auto-syncs with Atlas MongoDB in cloud. Two-way sync without writing sync logic manually.

For most projects — first strategy. Second justified for complex offline-mode requirements.

API with Mongoose on Node.js

// Schema with validation
const productSchema = new Schema({
    _id: { type: String, default: () => new ObjectId().toHexString() },
    title: { type: String, required: true, maxlength: 200 },
    categoryId: { type: String, required: true, index: true },
    priceCents: { type: Number, required: true, min: 0 },
    images: [{ url: String, width: Number, height: Number }],
    tags: [{ type: String, index: true }],
    metadata: Schema.Types.Mixed,        // flexible field for extensible data
    isActive: { type: Boolean, default: true, index: true },
    createdAt: { type: Date, default: Date.now, index: true }
}, {
    collection: 'products',
    versionKey: false
})

// Compound index for typical mobile queries
productSchema.index({ categoryId: 1, isActive: 1, createdAt: -1 })
productSchema.index({ tags: 1, isActive: 1 })

Most common mistake — forget index: true on fields filtered. MongoDB without index does collection scan — on 100K documents this is seconds instead of milliseconds.

Aggregation Pipeline for Mobile API

find() with simple filters — for simple queries. For statistics, complex selects, collection joins — aggregation pipeline:

// Catalog with product counts by categories
const categoriesWithCount = await Category.aggregate([
    { $match: { isActive: true } },
    {
        $lookup: {
            from: 'products',
            let: { categoryId: '$_id' },
            pipeline: [
                { $match: { $expr: { $and: [
                    { $eq: ['$categoryId', '$$categoryId'] },
                    { $eq: ['$isActive', true] }
                ]}}},
                { $count: 'total' }
            ],
            as: 'productCount'
        }
    },
    {
        $project: {
            name: 1,
            slug: 1,
            imageUrl: 1,
            productCount: { $ifNull: [{ $first: '$productCount.total' }, 0] }
        }
    },
    { $sort: { sortOrder: 1 } }
])

Atlas Search for Full-Text Search

Full-text search via Atlas Search (Lucene underneath) faster than regex or text index:

// Atlas Search index definition (in Atlas Console or via Atlas API)
const searchResults = await Product.aggregate([
    {
        $search: {
            index: 'product_search',
            compound: {
                must: [{
                    text: {
                        query: searchQuery,
                        path: ['title', 'description'],
                        fuzzy: { maxEdits: 1 }
                    }
                }],
                filter: [{ equals: { path: 'isActive', value: true } }]
            }
        }
    },
    { $limit: 20 },
    { $project: { title: 1, priceCents: 1, thumbnailUrl: 1, score: { $meta: 'searchScore' } } }
])

Fuzzy search with maxEdits: 1 — finds "notebook" when searching for "notbook". For mobile search important: virtual keyboard adds typos.

Change Streams for Real-time

MongoDB Change Streams — analog of PostgreSQL LISTEN/NOTIFY. Backend subscribes to collection changes, broadcasts events to mobile clients via WebSocket:

const changeStream = Product.watch([
    { $match: { operationType: { $in: ['insert', 'update', 'delete'] } } }
], { fullDocument: 'updateLookup' })

changeStream.on('change', (change) => {
    if (change.operationType === 'update') {
        const updatedProduct = change.fullDocument
        wsServer.broadcast(`category:${updatedProduct.categoryId}`, {
            type: 'PRODUCT_UPDATED',
            data: updatedProduct
        })
    }
})

Change Streams require MongoDB replica set — in Atlas enabled by default.

Atlas Data API

For simple CRUD without custom backend, Atlas offers Data API — HTTP endpoints to MongoDB via HTTPS, auth via API keys or JWT. Mobile client makes REST requests directly.

Suitable for prototypes and simple apps. In production with custom business logic, Data API not flexible enough.

Setting up MongoDB Atlas, schemas, indexes, Atlas Search and API for mobile app: 1–2 weeks. Cost calculated individually.