mongo icon indicating copy to clipboard operation
mongo copied to clipboard

MongoError: "Invalid response header"

Open kaldaf opened this issue 2 years ago • 9 comments

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)

err

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?

kaldaf avatar Apr 11 '22 07:04 kaldaf

are you sure your ENVs are set?

MONGO_URI ? MONGO_URI : "") looks very unsafe

lucsoft avatar Apr 11 '22 08:04 lucsoft

It's temporary, I also had a hard URI there, same error.

kaldaf avatar Apr 11 '22 08:04 kaldaf

@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 avatar Apr 11 '22 08:04 erfanium

@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)

kaldaf avatar Apr 11 '22 08:04 kaldaf

And about mongo atlas: VERSION - 5.0.6 REGION - AZURE Netherlands (westeurope) CLUSTER TIER - M0 Sandbox (General)

Maybe problem with Azure?

kaldaf avatar Apr 11 '22 08:04 kaldaf

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)

lucsoft avatar Apr 11 '22 09:04 lucsoft

Screenshot from 2022-04-11 13-43-39

This should works (the database behind https://mongo-demo.deno.dev)

erfanium avatar Apr 11 '22 09:04 erfanium

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 avatar Jun 16 '22 17:06 BrunoBernardino

@BrunoBernardino for now: https://github.com/erfanium/atlas_sdk is my current option

erfanium avatar Jun 16 '22 18:06 erfanium

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)

0xxFF avatar May 26 '23 10:05 0xxFF

Bro go to netwrok access add ip address click Allow from anywhere

Torjoy81 avatar Jun 21 '23 10:06 Torjoy81