Closed SpreeHertz closed 1 year ago
When MongoDB is used for saving data, the server crashes with an error (see below).
src/main.ts
import { PlayerChatEvent, ServerCommands } from '@customrealms/core'; import { Schema, model, connect } from 'mongoose'; // First: Save the location ServerCommands.register(`/savelocation {location}...`, async (player, call) => { // Get the coordinates const locationX = player.getTargetBlock()?.getX(); const locationY = player.getTargetBlock()?.getY(); const locationZ = player.getTargetBlock()?.getZ(); // Get location name const locationName = call.getPlaceholder('location')!; interface ILocations { locationName: string, locationX: number, locationY: number, locationZ: number } // Make the schema const locationSchema = new Schema<ILocations>({ locationName: { type: String, required: true }, locationX: { type: Number, required: true }, locationY: { type: Number, required: true }, locationZ: { type: Number, required: true } }) const Location = model<ILocations>('Locations', locationSchema); run().catch(err => console.log(err)) async function run() { // Connect to MongoDB await connect("string"); const loc = new Location({ locationName: `${locationName}`, locationX: `${locationX}`, locationY: `${locationY}`, locationZ: `${locationZ}` }); await loc.save(); } console.log(`${player.getDisplayName()} has saved a location named "${locationName}". X: ${locationX} / Y: ${locationY} / Z: ${locationZ}`) player.sendMessage(`Your location named "${locationName}" has been saved.\nX: ${locationX} / Y: ${locationY} / Z: ${locationZ}`) })
Description
When MongoDB is used for saving data, the server crashes with an error (see below).
Code
src/main.ts
Error message: