mongo
mongo copied to clipboard
MongoError: "Invalid response header"
Hi, I'm trying connect to MongoDb Atlas.
On localhost everything is OK, but when I deploy project on Deno Deploy it throw this error:
Error: MongoError: "Invalid response header" at WireProtocol.receive (https://deno.land/x/[email protected]/src/protocol/protocol.ts:77:38)
I already have on Mongo network access with Deno Deploy IP.
This is my usage of your module: mongodb.ts
import { MongoClient } from "./deps.ts";
import "https://deno.land/x/[email protected]/load.ts";
const client = new MongoClient();
const MONGO_URI = Deno.env.get("MONGO_URI");
const db = await client.connect(MONGO_URI ? MONGO_URI : "");
export default db;
app.ts
import db from "../mongodb.ts";
const usersCollection = db.collection<IUserModel>("users");
export const authLogin = async(ctx: Context) =>
{
if (!ctx.request.hasBody) ctx.throw(Status.BadRequest, "Bad Request");
const model = await ctx.request.body().value;
if (!model) ctx.throw(Status.BadRequest, "Bad Request");
const user = await usersCollection.findOne(
{ email: model.email },
{ noCursorTimeout: false }
);
... // more code
}
As I say on localhost, everything works, but when I deploy it, it throw Crash Report.
Any idea how to solve this?
are you sure your ENVs are set?
MONGO_URI ? MONGO_URI : "")
looks very unsafe
It's temporary, I also had a hard URI there, same error.
@kaldaf You mean you can access MongoDB Atlas via local system but not Deno Deploy? BTW https://mongo-demo.deno.dev/ is a demo with MongoDB Atlas free M0 tier deployed on Deno Deploy and works well
@erfanium Yes
I switched it to:
import { MongoClient } from "./deps.ts";
const client = new MongoClient();
const db = await client.connect("mongodb+srv://NAME:[email protected]/DB?authMechanism=SCRAM-SHA-1");
export default db;
And same err:
isolate start time: 2 milliseconds 1 Error: MongoError: "Invalid response header" at WireProtocol.receive (https://deno.land/x/[email protected]/src/protocol/protocol.ts:77:38)
And about mongo atlas: VERSION - 5.0.6 REGION - AZURE Netherlands (westeurope) CLUSTER TIER - M0 Sandbox (General)
Maybe problem with Azure?
We have problems with MongoDB Atlas, if i have more time i wanna look into better Altas support but my finals are less then a month away after that i have more time (i think)
This should works (the database behind https://mongo-demo.deno.dev)
I also have this problem sporadically with M2 in Cloud Atlas. I think it's when the primary server in the cluster switches, but basically for a few minutes this error shows up and blocks everything.
If there's something I can do to improve support on this, I'm happy to help.
@BrunoBernardino for now: https://github.com/erfanium/atlas_sdk is my current option
I also had the same problem. I solved it by allowing network access from 0.0.0.0/0 (I only had my local ip set)
Bro go to netwrok access add ip address click Allow from anywhere