Skip to content

Instantly share code, notes, and snippets.

@am-MongoDB
am-MongoDB / playground.js
Created January 23, 2025 12:15
See the impact on document size of design decisions on the structure within a document
// This is a playground for MongoDB for VS Code Extension.
// It creates 6 collections that each contain 1 document. All 6 collections
// contain the same information but with different field names. This is to
// demonstrate the different ways that MongoDB can store the same data and what
// impact your design decisions have on document size (and therefore how many
// documents can fit in the database cache → performance).
use('FieldNames');
const schema1 = db.getCollection('schema1');
const schema2 = db.getCollection('schema2');
import Realm from "realm";
// Set your Schema
const ListingSchema = {
name: "Listing",
primaryKey: "_id",
properties: {
_id: "objectId",
location: "string",
price: "int",
init() {
loginPublisher
.receive(on: DispatchQueue.main)
.flatMap { user -> RealmPublishers.AsyncOpenPublisher in
self.shouldIndicateActivity = true
var realmConfig = user.configuration(partitionValue: "user=\(user.id)")
realmConfig.objectTypes = [User.self, Project.self]
return Realm.asyncOpen(configuration: realmConfig)
}
.receive(on: DispatchQueue.main)
import SwiftUI
import RealmSwift
let app = App(id: "tasktracker-xxxxx") // TODO: Set the Realm application ID
@main
struct swiftui_realmApp: SwiftUI.App {
@StateObject var state = AppState()
var body: some Scene {
@am-MongoDB
am-MongoDB / open-app.bash
Created February 19, 2021 10:36
Open task-tracker app in Xcode
git clone https://github.com/ClusterDB/task-tracker-swiftui.git
cd task-tracker-swiftui
pod install --repo-update
open task-tracker-swiftui.xcworkspace
@am-MongoDB
am-MongoDB / app-tech.md
Last active February 19, 2021 10:23
App Technologies
In 🔥 Out ❄️
Swift Objective C
SwiftUI UIKit
Combine RxSwift
Realm Core Data
MongoDB Realm Sync (where needed) Home-baked cross-platform data sync
{"collections": [
{
"_comment": "Customer collection",
"customerID": 123456,
"name": {
"title": "Mr",
"first": "Andrew",
"last": "Morgan"
},
"_passwordComment": "No need for user credentials as will use Google auth",
db.freedom.find(
{
acidTransaction: "NOW_ENABLED",
multiStatement: true,
familiarity: "like relational DB",
comfortFactor: "🧸 extra cuddly",
syntax: "oh so similar",
implementation: "even your gran could do it",
useCases: "wide open",
try: "MongoDB 4.0 today"
@am-MongoDB
am-MongoDB / MongoDB_insert.py
Created April 10, 2018 09:25
The code to add a single user using the MongoDB query language
from pymongo import MongoClient
def addUser(database, user):
return database.customers.insert_one(user).inserted_id
client = MongoClient(port=27017)
db=client.store
# This is the object that the application would be working with anyway and
@am-MongoDB
am-MongoDB / sql_insert.py
Created April 10, 2018 09:22
The code required to insert a single user using SQL
import mysql.connector
from mysql.connector import errorcode
def addUser(connection, user):
cursor = connection.cursor()
customerInsert = (
"INSERT INTO customer (first_name, last_name, email, "
"DOB, annual_spend) VALUES "
"(%(first)s, %(last)s, %(email)s, %(dob)s, %(spend)s)")